<template>
  <div>
    <div class="top-panel">
      <el-card>
        <el-form label-width="70px" label-position="right">
          <el-row :gutter="10">
            <el-col :span="5">
              <el-form-item label="加入日期">
                <el-date-picker
                    v-model="searchForm.createTimeRange"
                    type="daterange"
                    range-separator="~"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    value-format="YYYY-MM-DD"
                    @change="loadDataList"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="最近使用日期" label-width="100">
                <el-date-picker
                    v-model="searchForm.lastUseTimeRange"
                    type="daterange"
                    range-separator="~"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    value-format="YYYY-MM-DD"
                    @change="loadDataList"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="品牌" label-width="60px">
                <el-input
                    v-model="searchForm.deviceBrandFuzzy"
                    clearable
                    placeholder="支持模糊搜索"
                    @keyup.enter.native="loadDataList">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="设备ID" label-width="60px">
                <el-input
                    v-model="searchForm.deviceIdFuzzy"
                    clearable
                    placeholder="支持模糊搜索"
                    @keyup.enter.native="loadDataList">
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="5" :style="{paddingLeft:'10px'}">
              <el-button-group>
                <el-button type="success" @click="loadDataList()">查询</el-button>
              </el-button-group>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
    </div>
    <!-- 内容区域 -->
    <el-card :style="{ height: 'calc(100vh - 192px)',marginTop:'10px'}">
      <template #header>
        <span>问题列表</span>
      </template>
      <Table
          ref="tableInfoRef"
          :columns="columns"
          :fetch="loadDataList"
          :dataSource="tableData"
          :options="tableOptions"
          :extHeight="tableOptions.extHeight"
      >
      </Table>
    </el-card>
  </div>
</template>


<script setup>
import {ref, getCurrentInstance} from "vue";

const {proxy} = getCurrentInstance();
const api = {
  loadDataList: "/appUser/loadDeviceList",
}

const searchForm = ref({})

const tableData = ref({});
const tableOptions = ref({
  extHeight: 125,
})

const columns = [
  {
    label: "登录设备",
    prop: "deviceId",
  },
  {
    label: "设备品牌",
    prop: "deviceBrand",
  },
  {
    label: "创建时间",
    prop: "createTime",
  },
  {
    label: "最近使用时间",
    prop: "lastUseTime",
  },
  {
    label: "登录IP",
    prop: "ip",
  },
]

const tableInfoRef = ref();

const loadDataList = async () => {
  let params = {
    pageNo: tableData.value.pageNo,
    pageSize: tableData.value.pageSize,
    ...searchForm.value
  }
  if (params.createTimeRange) {
    params.createTimeStart = searchForm.value.createTimeRange[0];
    params.createTimeEnd = searchForm.value.createTimeRange[1];
  }
  if (params.lastUseTimeRange) {
    params.lastUseTimeStart = searchForm.value.lastUseRange[0];
    params.lastUseTimeEnd = searchForm.value.lastUseRange[1];
  }
  delete params.createTimeRange;
  delete params.lastUseTimeRange;
  let result = await proxy.Request({
    url: api.loadDataList,
    params: params,
  })
  if (!result) {
    return;
  }
  tableData.value = result.data;
}


</script>


<style scoped lang="scss">
.box-card {
  .top {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .tree-panel {
    overflow: auto;
    height: calc(100vh - 304px);
  }
}
</style>
